<template>
  <div></div>
</template>
<script>
export default {
  data() {
    return {};
  },
  methods: {
    fn1(str) {
      let tempArr = str.split(" ");
      return tempArr[tempArr.length - 1].length;
    },
    fn2(str) {
      // 读入一个字符串str，输出字符串str中的连续最长的数字串
      let reg = /[\d]+/g;
      console.log(str.match(reg));
      let tempArr = str.match(reg);
      let result = tempArr.reduce((pre, item) => {
        let temp = pre ? (pre.length >= item.length ? pre : item) : item;
        return temp;
      }, "");

      console.log("result=", result);
      return result;
    },

    fn3(str) {
      // 括号匹配深度
      let leftArr = [];
      let rightArr = []
      let len = 0;
    
      let arr = str.split("");
      for (let index = 0; index < arr.length; index++) {
        let item = arr[index];

           if (item == "{" || item == "(" || item == "[") {
          leftArr.push(item);
        } else if(item==")"||item=="}"||item=="]"){
            rightArr.push(item)
          let temp = leftArr[leftArr.length - 1];
          let tempStr = temp + item
          if (tempStr == '()' || tempStr == '{}' || tempStr == '[]') {
            rightArr.pop()
            leftArr.pop();
            len++
          } else {
            break;
          }
        }
      }
console.log('leftArr=',leftArr);
console.log('rightArr=',rightArr);
      if (leftArr.length || rightArr.length) {
          len = 0
      }
    
      console.log("len=", len);

    },
    test() {
      /* let str = 'hello nowcoder'
            return  this.fn1(str) */

      /* let str = "abcd12345ed125ss123456789";
      return this.fn2(str); */

    //   let str = "{[{}]}";
      let str = "()(){()}";
      this.fn3(str);
    },
  },
  mounted() {
    console.log(this.test());
  },
};
</script>